package org.example.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apiguardian.api.API;
import org.example.exception.AppException;
import org.example.exception.AppExceptionCodeMsg;
import org.example.pojo.Department;
import org.example.query.DepartmentQuery;
import org.example.service.IDepartmentService;
import org.example.vo.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author peak
 * @since 2024-12-18
 */
@Api(value = "部门管理",description = "部门管理")
@RestController
@RequestMapping("/department")
public class DepartmentController extends BaseController<Department, DepartmentQuery> {
    //这里还得写 那个删除的标记
    @Autowired
    private IDepartmentService departmentService;

    @RequestMapping("/change/delmark")
    public ResultBean changeDelmark(@RequestBody Department department) {

        if(department == null ||
        department.getId()==null ||
        department.getId()==0 ||
        department.getDelmark()==null) {
            throw new AppException(AppExceptionCodeMsg.PARAMS_EMPTY);
        }
        UpdateWrapper<Department> updateWrapper = new UpdateWrapper<Department>();
        updateWrapper.set("delmark", department.getDelmark())
                .eq("id", department.getId());
        //只是更新删除标记，逻辑删除
        Boolean result = departmentService.update(updateWrapper);

        return result?ResultBean.SUCCESS():ResultBean.ERROR("修改部门删除部门失败");
    }
    @ApiOperation("根据类型查询")
    @GetMapping("/type/{type}")
    public ResultBean getType(@PathVariable("type") String type) {
        List<Department> departments = departmentService.list(new QueryWrapper<Department>().eq("dept_type",type));
        return  ResultBean.SUCCESS(departments);
    }
}
